//
//  HJScreenView.m
//  Sneakers
//
//  Created by 胡光健 on 2017/9/26.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HJScreenView.h"
#import "NMRangeSlider.h"

@interface HJScreenView ()
@property (weak, nonatomic) IBOutlet UIView *supView;
@end

@implementation HJScreenView

-(instancetype)init {
    if (self = [super init]) {
        self = [[[NSBundle mainBundle]loadNibNamed:@"HJScreenView" owner:nil options:nil] firstObject];
        [self create];
    }
    return self;
}
-(void)layoutSubviews {
    [super layoutSubviews];
    self.slider.frame = CGRectMake(0, 2, self.supView.frame.size.width, 30);
    
}
-(void)awakeFromNib {
    [super awakeFromNib];
//    [self create];
}

-(void)create {
    //设置默认值
    self.max = 5000;
    self.min = 0;
    self.slider = [[NMRangeSlider alloc] init];
    NSNumber * sliderMin =  [[NSUserDefaults standardUserDefaults] objectForKey:@"min"];
    NSNumber * sliderMax =  [[NSUserDefaults standardUserDefaults] objectForKey:@"max"];
    NSString * price = [[NSUserDefaults standardUserDefaults] objectForKey:@"priceNotext"];
//    self.slider.maximumValue = [sliderMax doubleValue] ? [sliderMax doubleValue] : 1.0;
//    self.slider.minimumValue = [sliderMin doubleValue] ? [sliderMin doubleValue] : 0.0;
//    [self.slider setLowerValue:[sliderMin doubleValue] ? [sliderMin doubleValue] : 0.0 upperValue:[sliderMax doubleValue] ? [sliderMax doubleValue] : 1.0 animated:YES];
    self.slider.lowerValue = [sliderMin doubleValue] ? [sliderMin doubleValue] : 0.0;
    self.slider.upperValue = [sliderMax doubleValue] ? [sliderMax doubleValue] : 1.0;
    self.priceNo.text = price;
    
    
    self.slider.trackImage = [UIImage imageNamed:@"line"];
    self.slider.trackBackgroundImage = [UIImage imageWithColor:HJColorRGB(246)];
    self.slider.lowerHandleImageNormal = [UIImage imageNamed:@"yuan"];
    self.slider.lowerHandleImageHighlighted = [UIImage imageNamed:@"yuan"];
    self.slider.upperHandleImageNormal = [UIImage imageNamed:@"yuan"];
    self.slider.upperHandleImageHighlighted = [UIImage imageNamed:@"yuan"];
    [self.slider addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventTouchUpInside];
    [self.supView addSubview:self.slider];
    
}


-(void)valueChange:(NMRangeSlider *)slider {
    self.min = slider.lowerValue * 5000;
    self.max = slider.upperValue * 5000;
    self.priceNo.text = [NSString stringWithFormat:@"￥%ld~￥%ld+",self.min,self.max];

    if (self.maxAndminBlock) {
        self.maxAndminBlock(slider.upperValue, slider.lowerValue);
    }
   
}
@end
